/**
 * 
 */
package com.blazegame.logging.async;


import com.blazegame.logging.LogLevel;
import com.blazegame.logging.Logger;
import com.blazegame.logging.LoggerUtils;


/**
 * 异步logger
 * @author JackChu
 * @version 2011-7-8 下午01:09:11
 */
public class AsyncLogger implements Logger{

	private Logger concretelogger;

	/**
	 * @param logger
	 */
	public AsyncLogger(Logger concretelogger) {
		this.concretelogger = concretelogger;
	}

	@Override
	public boolean isDebugEnabled(){
		return concretelogger.isDebugEnabled();
	}
	
	@Override
	public boolean isInfoEnabled() {
		return concretelogger.isInfoEnabled();
	}

	@Override
	public void trace(String msg, String... args) {
		
	}

	@Override
	public void trace(String msg, Throwable ex, String... args) {
		
	}

	@Override
	public boolean isTraceEnabled() {
		return false;
	}

	@Override
	public void debug(String msg, String... args) {
		if(isDebugEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), null, LogLevel.DEBUG));
		}
		
	}

	@Override
	public void debug(String msg, Throwable ex, String... args) {
		if(isDebugEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), ex, LogLevel.DEBUG));
		}
	}

	@Override
	public void info(String msg, String... args) {
		if(isInfoEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), null, LogLevel.DEBUG));
		}
		
	}

	@Override
	public void info(String msg, Throwable ex, String... args) {
		if(isInfoEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), ex, LogLevel.DEBUG));
		}
		
	}

	@Override
	public boolean isWarnEnabled() {
		return concretelogger.isWarnEnabled();
	}

	@Override
	public void warn(String msg, String... args) {
		if(isWarnEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), null, LogLevel.WARN));
		}
		
	}

	@Override
	public void warn(String msg, Throwable ex, String... args) {
		if(isWarnEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), ex, LogLevel.WARN));
		}		
	}

	@Override
	public boolean isErrorEnabled() {
		return concretelogger.isErrorEnabled();
	}

	@Override
	public void error(String msg, String... args) {
		if(isErrorEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), null, LogLevel.ERROR));
		}		
	}

	@Override
	public void error(String msg, Throwable ex, String... args) {
		if(isErrorEnabled()){
			LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), ex, LogLevel.ERROR));
		}			
	}

	@Override
	public void fatal(String msg, String... args) {
		LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), null, LogLevel.FATAL));		
	}

	@Override
	public void fatal(String msg, Throwable ex, String... args) {
		LoggerExecutor.put(new LogTask(concretelogger, LoggerUtils.format(msg, args), ex, LogLevel.FATAL));		
	}




}
